import request from "@/utils/request";

// 查询代理商信息列表
export function listAgent(query) {
  return request({
    url: "/agent/agent/list",
    method: "get",
    params: query,
  });
}

// 查询代理商信息详细
export function getAgent(id) {
  return request({
    url: "/agent/agent/" + id,
    method: "get",
  });
}

// 新增代理商信息
export function addAgent(data) {
  return request({
    url: "/agent/agent",
    method: "post",
    data: data,
  });
}

// 修改代理商信息
export function updateAgent(data) {
  return request({
    url: "/agent/agent",
    method: "put",
    data: data,
  });
}

// 删除代理商信息
export function delAgent(id) {
  return request({
    url: "/agent/agent/" + id,
    method: "delete",
  });
}
// 导出一个函数，用于获取个人银行列表
export function personalBankList() {
  return request({
    url: "/app/personal/bank/list",
    method: "get",
  });
}
// 获取银行列表
export function bankList() {
  return request({
    url: "/app/common/bank/list",
    method: "get",
  });
}
// 获取支行列表
export function branchList(bankId) {
  return request({
    url: "/agent/branch/list",
    method: "get",
    params: { bankId },
  });
}
// 查询区域信息-全国
export function districtList(params = {}) {
  return request({
    url: "/system/district/list",
    method: "get",
    params: params,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
  });
}

// 新增代理商信息/修改代理商信息
export function agent(bankId) {
  return request({
    url: "/agent/agent",
    method: "POST",
    params: { bankId },
  });
}

// 新增银行卡
export function addBankCard(data) {
  return request({
    url: "/agent/agent/addBankCard",
    method: "post",
    data: data,
  });
}

// 配置分润比例
export function addRatio(data) {
  return request({
    url: "/agent/agent/addRatio",
    method: "post",
    data: data,
  });
}

// 代理商信息详情
export function getAgentInfo(id) {
  return request({
    url: "/agent/agent/info/"+id,
    method: "get",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
  });
}

// 重置密码
export function resetPassword(userName) {
  const params = new URLSearchParams();
  params.append('userName', userName);
  
  return request({
    url: "/agent/agent/updPwd",
    method: "post",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
    data: params
  });
}

// 更新云服务提供商ID
export function updateProviderId(id, providerId) {
  return request({
    url: "/agent/agent/updateProviderId",
    method: "put",
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    data: {
      id,
      providerId
    }
  });
}